package nuc.edu.tlias.controller;

import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import nuc.edu.tlias.pojo.Emp;
import nuc.edu.tlias.pojo.EmpQueryParam;
import nuc.edu.tlias.pojo.PageResult;
import nuc.edu.tlias.pojo.Result;
import nuc.edu.tlias.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    EmpService empService;

    @GetMapping
    public Result page(EmpQueryParam empQueryParam) {
        log.info("分页查询：{}",empQueryParam);
        PageResult<Emp> pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }
    @GetMapping("/list")
    public Result findall(){

        List<Emp> list =  empService.findall();
        return Result.success(list);
    }

    @PostMapping
    public Result save(@RequestBody Emp emp){
        empService.save(emp);


        return Result.success();
    }
    @DeleteMapping
    public Result delete(Integer[] ids){
        log.info("删除员工：{}", Arrays.toString(ids));
        empService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        log.info("接收参数：{}",id);
        Emp emp =  empService.findById(id);

        return Result.success(emp);
    }


    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("请求体接收：{}",emp);

            empService.update(emp);
        return Result.success();
    }

}
